#include<iostream>
#include<string.h>

class string
{
    //友元声明
    friend std::ostream& operator<<(std::ostream& out,string& str);
    friend std::istream& operator>>(std::istream& in,string& str);
public:
    //实现迭代器;
    typedef char* iterator;
    typedef const char* const_iterator;

    iterator begin()
    {
        return _str;
    }
    iterator end()
    {
        return _str+_size;//指向末尾的'\0'
    }
    const_iterator begin()const 
    {
        return _str;
    }
    const_iterator end()const
    {
        return _str+_size;//指向末尾的'\0'
    }
    
public:
    string(const char* str="");
    string(const string& s);

    const char* c_str()const;
    size_t size()const;
    size_t capacity()const;

    void reserve(int n=0);
    void resize(size_t n,char ch='\0');

    void push_back(char ch);
    void append(const char* str);
    void insert(int pos,char ch);
    void insert(int pos,const char* str);
    void clear();
    void erase(int pos,size_t len=npos);
    size_t find(const char* str, size_t pos=0);
    string substr(size_t pos=0,size_t len=npos);

    char& operator[](int pos);
    const char& operator[](int pos)const; 

    string& operator+=(char ch);
    string& operator+=(const char* str);
    string& operator=(string str);

    bool operator<(const string& str);
    bool operator==(const string& str);
    bool operator<=(const string& str);
    bool operator>(const string& str);
    bool operator>=(const string& str);
    bool operator!=(const string& str);

    ~string();
private:
    char* _str;
    size_t _size;
    size_t _capacity;
    const static size_t npos=-1;
};